package utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * Created by shiqianjin on 2016/10/5.
 */
//adapter基类
public abstract class AdapterUtils<T> extends BaseAdapter {
    protected Context mcontext;
    protected List<T> totalList = null;
    protected LayoutInflater mInflater = null;

    public AdapterUtils(Context mcontext,List<T> totalList){
        this.mcontext = mcontext;
        this.totalList = totalList;
        mInflater = (LayoutInflater) mcontext.getSystemService(mcontext.LAYOUT_INFLATER_SERVICE  );
    }
    @Override
    public int getCount() {
        return totalList.size();
    }

    @Override
    public Object getItem(int position) {
        return totalList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return getMyView(position, convertView, parent);
    }

    public abstract View getMyView(int position, View convertView, ViewGroup parent);
    public void relodListView(List<T> list,boolean isClear){
        if (isClear){
            totalList.clear();
        }
        totalList.addAll(list);
        notifyDataSetChanged();
    }
}
